<template>
  <div>
    <div class="gva-search-box">
      <el-form ref="elSearchFormRef" :inline="true" :model="searchInfo" class="demo-form-inline" :rules="searchRule" @keyup.enter="onSubmit">
      <el-form-item label="创建日期" prop="createdAt">
      <template #label>
        <span>
          创建日期
          <el-tooltip content="搜索范围是开始日期（包含）至结束日期（不包含）">
            <el-icon><QuestionFilled /></el-icon>
          </el-tooltip>
        </span>
      </template>
      <el-date-picker v-model="searchInfo.startCreatedAt" type="datetime" placeholder="开始日期" :disabled-date="time=> searchInfo.endCreatedAt ? time.getTime() > searchInfo.endCreatedAt.getTime() : false"></el-date-picker>
       —
      <el-date-picker v-model="searchInfo.endCreatedAt" type="datetime" placeholder="结束日期" :disabled-date="time=> searchInfo.startCreatedAt ? time.getTime() < searchInfo.startCreatedAt.getTime() : false"></el-date-picker>
      </el-form-item>
      
        <el-form-item>
          <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
          <el-button icon="refresh" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="gva-table-box">
        <div class="gva-btn-list">
            <el-button type="primary" icon="plus" @click="openDialog">新增</el-button>
            <el-button icon="delete" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="onDelete">删除</el-button>
            <el-button type="primary" icon="plus" @click="syncHrUser">同步</el-button>
          </div>
        <el-table
        ref="multipleTable"
        style="width: 100%"
        tooltip-effect="dark"
        :data="tableData"
        row-key="ID"
        @selection-change="handleSelectionChange"
        >
        <el-table-column type="selection" width="55" />
        
        <el-table-column align="left" label="日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.CreatedAt) }}</template>
        </el-table-column>
        
        <el-table-column align="left" label="员工ID" prop="EmployeeId" width="120" />
        <el-table-column align="left" label="工号" prop="EnCode" width="120" />
        <el-table-column align="left" label="员工类型" prop="TypeId" width="120" />
        <el-table-column align="left" label="姓名" prop="FullName" width="120" />
        <el-table-column align="left" label="性别" prop="Gender" width="120" />
        <el-table-column align="left" label="头像" prop="HeadPic" width="120" />
        <el-table-column align="left" label="证件类型" prop="IDType" width="120" />
        <el-table-column align="left" label="身份证号码" prop="IDNumber" width="120" />
        <el-table-column align="left" label="身份证有效期" prop="IDValidityDate" width="120" />
         <el-table-column align="left" label="出生日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.Birthday) }}</template>
         </el-table-column>
        <el-table-column align="left" label="发证机关" prop="Organ" width="120" />
        <el-table-column align="left" label="家庭地址" prop="FamilyAddress" width="120" />
        <el-table-column align="left" label="健康状态" prop="Health" width="120" />
        <el-table-column align="left" label="岗位类型" prop="PostType" width="120" />
        <el-table-column align="left" label="岗位性质" prop="PostNature" width="120" />
        <el-table-column align="left" label="岗位类别" prop="PostClass" width="120" />
        <el-table-column align="left" label="职位" prop="JobName" width="120" />
        <el-table-column align="left" label="职称" prop="JobTitle" width="120" />
        <el-table-column align="left" label="员工等级" prop="Rank" width="120" />
        <el-table-column align="left" label="RankName字段" prop="RankName" width="120" />
        <el-table-column align="left" label="CompanyId字段" prop="CompanyId" width="120" />
        <el-table-column align="left" label="所属部门" prop="DepartmentId" width="120" />
        <el-table-column align="left" label="所属部门" prop="DepartmentClass" width="120" />
        <el-table-column align="left" label="部门类别" prop="PostId" width="120" />
        <el-table-column align="left" label="岗位名称" prop="PostName" width="120" />
        <el-table-column align="left" label="级别" prop="GradeId" width="120" />
        <el-table-column align="left" label="级别分类" prop="GradeClass" width="120" />
        <el-table-column align="left" label="简历Id" prop="ResumeId" width="120" />
         <el-table-column align="left" label="入职日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.JoinDate) }}</template>
         </el-table-column>
         <el-table-column align="left" label="试用期截止日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.TrialEndTime) }}</template>
         </el-table-column>
        <el-table-column align="left" label="IsTrial字段" prop="IsTrial" width="120" />
        <el-table-column align="left" label="TrailAuditMark字段" prop="TrailAuditMark" width="120" />
        <el-table-column align="left" label="STrailAuditMark字段" prop="STrailAuditMark" width="120" />
         <el-table-column align="left" label="加薪日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.TrailRaiseDate) }}</template>
         </el-table-column>
        <el-table-column align="left" label="IsTrailRaise字段" prop="IsTrailRaise" width="120" />
        <el-table-column align="left" label="ID卡号" prop="IdCard" width="120" />
         <el-table-column align="left" label="岗位奖金生效日期" width="180">
            <template #default="scope">{{ formatDate(scope.row.EffectiveDate) }}</template>
         </el-table-column>
        <el-table-column align="left" label="国籍" prop="Country" width="120" />
        <el-table-column align="left" label="籍贯" prop="Native" width="120" />
        <el-table-column align="left" label="民族" prop="Nation" width="120" />
        <el-table-column align="left" label="最高学历" prop="Education" width="120" />
        <el-table-column align="left" label="手提电话" prop="Mobile" width="120" />
        <el-table-column align="left" label="婚姻状况" prop="Marriage" width="120" />
        <el-table-column align="left" label="考勤卡号" prop="AttendanceCode" width="120" />
         <el-table-column align="left" label="工齡起算日" width="180">
            <template #default="scope">{{ formatDate(scope.row.WorkageCountOn) }}</template>
         </el-table-column>
        <el-table-column align="left" label="工资薪酬ID" prop="SalaryId" width="120" />
        <el-table-column align="left" label="岗位奖金类型" prop="PostBonusId" width="120" />
        <el-table-column align="left" label="岗位奖金金额" prop="BonusWage" width="120" />
        <el-table-column align="left" label="放假组别" prop="HolidayGroupId" width="120" />
        <el-table-column align="left" label="考勤组别" prop="AttendanceGroupId" width="120" />
        <el-table-column align="left" label="地区" prop="Area" width="120" />
        <el-table-column align="left" label="UrgentContacts字段" prop="UrgentContacts" width="120" />
        <el-table-column align="left" label="UrgentContactPhone字段" prop="UrgentContactPhone" width="120" />
        <el-table-column align="left" label="入职介绍人" prop="Recommender" width="120" />
        <el-table-column align="left" label="RecommMobile字段" prop="RecommMobile" width="120" />
        <el-table-column align="left" label="状态，1--正常，2--离职，3--黑名单" prop="Status" width="120" />
        <el-table-column align="left" label="删除标记" prop="DeleteMark" width="120" />
         <el-table-column align="left" label="修改时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.LeaveDate) }}</template>
         </el-table-column>
        <el-table-column align="left" label="有效标志" prop="EnabledMark" width="120" />
        <el-table-column align="left" label="备注" prop="Description" width="120" />
         <el-table-column align="left" label="创建时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.CreateDate) }}</template>
         </el-table-column>
        <el-table-column align="left" label="创建用户主键" prop="CreateUserId" width="120" />
        <el-table-column align="left" label="创建用户" prop="CreateUserName" width="120" />
         <el-table-column align="left" label="修改时间" width="180">
            <template #default="scope">{{ formatDate(scope.row.ModifyDate) }}</template>
         </el-table-column>
        <el-table-column align="left" label="修改用户主键" prop="ModifyUserId" width="120" />
        <el-table-column align="left" label="修改用户" prop="ModifyUserName" width="120" />
        <el-table-column align="left" label="操作" fixed="right" min-width="240">
            <template #default="scope">
            <el-button type="primary" link class="table-button" @click="getDetails(scope.row)">
                <el-icon style="margin-right: 5px"><InfoFilled /></el-icon>
                查看详情
            </el-button>
            <el-button type="primary" link icon="edit" class="table-button" @click="updateHrEmployeeFunc(scope.row)">变更</el-button>
            <el-button type="primary" link icon="delete" @click="deleteRow(scope.row)">删除</el-button>
            </template>
        </el-table-column>
        </el-table>
        <div class="gva-pagination">
            <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            :current-page="page"
            :page-size="pageSize"
            :page-sizes="[10, 30, 50, 100]"
            :total="total"
            @current-change="handleCurrentChange"
            @size-change="handleSizeChange"
            />
        </div>
    </div>
    <el-drawer size="800" v-model="dialogFormVisible" :show-close="false" :before-close="closeDialog">
       <template #title>
              <div class="flex justify-between items-center">
                <span class="text-lg">{{type==='create'?'添加':'修改'}}</span>
                <div>
                  <el-button type="primary" @click="enterDialog">确 定</el-button>
                  <el-button @click="closeDialog">取 消</el-button>
                </div>
              </div>
            </template>

          <el-form :model="formData" label-position="top" ref="elFormRef" :rules="rule" label-width="80px">
            <el-form-item label="员工ID:"  prop="EmployeeId" >
              <el-input v-model="formData.EmployeeId" :clearable="true"  placeholder="请输入员工ID" />
            </el-form-item>
            <el-form-item label="工号:"  prop="EnCode" >
              <el-input v-model="formData.EnCode" :clearable="true"  placeholder="请输入工号" />
            </el-form-item>
            <el-form-item label="员工类型:"  prop="TypeId" >
              <el-input v-model="formData.TypeId" :clearable="true"  placeholder="请输入员工类型" />
            </el-form-item>
            <el-form-item label="姓名:"  prop="FullName" >
              <el-input v-model="formData.FullName" :clearable="true"  placeholder="请输入姓名" />
            </el-form-item>
            <el-form-item label="性别:"  prop="Gender" >
              <el-input v-model="formData.Gender" :clearable="true"  placeholder="请输入性别" />
            </el-form-item>
            <el-form-item label="头像:"  prop="HeadPic" >
              <el-input v-model="formData.HeadPic" :clearable="true"  placeholder="请输入头像" />
            </el-form-item>
            <el-form-item label="证件类型:"  prop="IDType" >
              <el-input v-model="formData.IDType" :clearable="true"  placeholder="请输入证件类型" />
            </el-form-item>
            <el-form-item label="身份证号码:"  prop="IDNumber" >
              <el-input v-model="formData.IDNumber" :clearable="true"  placeholder="请输入身份证号码" />
            </el-form-item>
            <el-form-item label="身份证有效期:"  prop="IDValidityDate" >
              <el-input v-model="formData.IDValidityDate" :clearable="true"  placeholder="请输入身份证有效期" />
            </el-form-item>
            <el-form-item label="出生日期:"  prop="Birthday" >
              <el-date-picker v-model="formData.Birthday" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="发证机关:"  prop="Organ" >
              <el-input v-model="formData.Organ" :clearable="true"  placeholder="请输入发证机关" />
            </el-form-item>
            <el-form-item label="家庭地址:"  prop="FamilyAddress" >
              <el-input v-model="formData.FamilyAddress" :clearable="true"  placeholder="请输入家庭地址" />
            </el-form-item>
            <el-form-item label="健康状态:"  prop="Health" >
              <el-input v-model="formData.Health" :clearable="true"  placeholder="请输入健康状态" />
            </el-form-item>
            <el-form-item label="岗位类型:"  prop="PostType" >
              <el-input v-model="formData.PostType" :clearable="true"  placeholder="请输入岗位类型" />
            </el-form-item>
            <el-form-item label="岗位性质:"  prop="PostNature" >
              <el-input v-model="formData.PostNature" :clearable="true"  placeholder="请输入岗位性质" />
            </el-form-item>
            <el-form-item label="岗位类别:"  prop="PostClass" >
              <el-input v-model="formData.PostClass" :clearable="true"  placeholder="请输入岗位类别" />
            </el-form-item>
            <el-form-item label="职位:"  prop="JobName" >
              <el-input v-model="formData.JobName" :clearable="true"  placeholder="请输入职位" />
            </el-form-item>
            <el-form-item label="职称:"  prop="JobTitle" >
              <el-input v-model="formData.JobTitle" :clearable="true"  placeholder="请输入职称" />
            </el-form-item>
            <el-form-item label="员工等级:"  prop="Rank" >
              <el-input v-model="formData.Rank" :clearable="true"  placeholder="请输入员工等级" />
            </el-form-item>
            <el-form-item label="RankName字段:"  prop="RankName" >
              <el-input v-model="formData.RankName" :clearable="true"  placeholder="请输入RankName字段" />
            </el-form-item>
            <el-form-item label="CompanyId字段:"  prop="CompanyId" >
              <el-input v-model="formData.CompanyId" :clearable="true"  placeholder="请输入CompanyId字段" />
            </el-form-item>
            <el-form-item label="所属部门:"  prop="DepartmentId" >
              <el-input v-model="formData.DepartmentId" :clearable="true"  placeholder="请输入所属部门" />
            </el-form-item>
            <el-form-item label="所属部门:"  prop="DepartmentClass" >
              <el-input v-model="formData.DepartmentClass" :clearable="true"  placeholder="请输入所属部门" />
            </el-form-item>
            <el-form-item label="部门类别:"  prop="PostId" >
              <el-input v-model="formData.PostId" :clearable="true"  placeholder="请输入部门类别" />
            </el-form-item>
            <el-form-item label="岗位名称:"  prop="PostName" >
              <el-input v-model="formData.PostName" :clearable="true"  placeholder="请输入岗位名称" />
            </el-form-item>
            <el-form-item label="级别:"  prop="GradeId" >
              <el-input v-model="formData.GradeId" :clearable="true"  placeholder="请输入级别" />
            </el-form-item>
            <el-form-item label="级别分类:"  prop="GradeClass" >
              <el-input v-model="formData.GradeClass" :clearable="true"  placeholder="请输入级别分类" />
            </el-form-item>
            <el-form-item label="简历Id:"  prop="ResumeId" >
              <el-input v-model="formData.ResumeId" :clearable="true"  placeholder="请输入简历Id" />
            </el-form-item>
            <el-form-item label="入职日期:"  prop="JoinDate" >
              <el-date-picker v-model="formData.JoinDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="试用期截止日期:"  prop="TrialEndTime" >
              <el-date-picker v-model="formData.TrialEndTime" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="IsTrial字段:"  prop="IsTrial" >
            </el-form-item>
            <el-form-item label="TrailAuditMark字段:"  prop="TrailAuditMark" >
              <el-input v-model.number="formData.TrailAuditMark" :clearable="true" placeholder="请输入TrailAuditMark字段" />
            </el-form-item>
            <el-form-item label="STrailAuditMark字段:"  prop="STrailAuditMark" >
              <el-input v-model.number="formData.STrailAuditMark" :clearable="true" placeholder="请输入STrailAuditMark字段" />
            </el-form-item>
            <el-form-item label="加薪日期:"  prop="TrailRaiseDate" >
              <el-date-picker v-model="formData.TrailRaiseDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="IsTrailRaise字段:"  prop="IsTrailRaise" >
            </el-form-item>
            <el-form-item label="ID卡号:"  prop="IdCard" >
              <el-input v-model="formData.IdCard" :clearable="true"  placeholder="请输入ID卡号" />
            </el-form-item>
            <el-form-item label="岗位奖金生效日期:"  prop="EffectiveDate" >
              <el-date-picker v-model="formData.EffectiveDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="国籍:"  prop="Country" >
              <el-input v-model="formData.Country" :clearable="true"  placeholder="请输入国籍" />
            </el-form-item>
            <el-form-item label="籍贯:"  prop="Native" >
              <el-input v-model="formData.Native" :clearable="true"  placeholder="请输入籍贯" />
            </el-form-item>
            <el-form-item label="民族:"  prop="Nation" >
              <el-input v-model="formData.Nation" :clearable="true"  placeholder="请输入民族" />
            </el-form-item>
            <el-form-item label="最高学历:"  prop="Education" >
              <el-input v-model="formData.Education" :clearable="true"  placeholder="请输入最高学历" />
            </el-form-item>
            <el-form-item label="手提电话:"  prop="Mobile" >
              <el-input v-model="formData.Mobile" :clearable="true"  placeholder="请输入手提电话" />
            </el-form-item>
            <el-form-item label="婚姻状况:"  prop="Marriage" >
              <el-input v-model="formData.Marriage" :clearable="true"  placeholder="请输入婚姻状况" />
            </el-form-item>
            <el-form-item label="考勤卡号:"  prop="AttendanceCode" >
              <el-input v-model="formData.AttendanceCode" :clearable="true"  placeholder="请输入考勤卡号" />
            </el-form-item>
            <el-form-item label="工齡起算日:"  prop="WorkageCountOn" >
              <el-date-picker v-model="formData.WorkageCountOn" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="工资薪酬ID:"  prop="SalaryId" >
              <el-input v-model="formData.SalaryId" :clearable="true"  placeholder="请输入工资薪酬ID" />
            </el-form-item>
            <el-form-item label="岗位奖金类型:"  prop="PostBonusId" >
              <el-input v-model="formData.PostBonusId" :clearable="true"  placeholder="请输入岗位奖金类型" />
            </el-form-item>
            <el-form-item label="岗位奖金金额:"  prop="BonusWage" >
              <el-input-number v-model="formData.BonusWage"  style="width:100%" :precision="2" :clearable="true"  />
            </el-form-item>
            <el-form-item label="放假组别:"  prop="HolidayGroupId" >
              <el-input v-model="formData.HolidayGroupId" :clearable="true"  placeholder="请输入放假组别" />
            </el-form-item>
            <el-form-item label="考勤组别:"  prop="AttendanceGroupId" >
              <el-input v-model="formData.AttendanceGroupId" :clearable="true"  placeholder="请输入考勤组别" />
            </el-form-item>
            <el-form-item label="地区:"  prop="Area" >
              <el-input v-model="formData.Area" :clearable="true"  placeholder="请输入地区" />
            </el-form-item>
            <el-form-item label="UrgentContacts字段:"  prop="UrgentContacts" >
              <el-input v-model="formData.UrgentContacts" :clearable="true"  placeholder="请输入UrgentContacts字段" />
            </el-form-item>
            <el-form-item label="UrgentContactPhone字段:"  prop="UrgentContactPhone" >
              <el-input v-model="formData.UrgentContactPhone" :clearable="true"  placeholder="请输入UrgentContactPhone字段" />
            </el-form-item>
            <el-form-item label="入职介绍人:"  prop="Recommender" >
              <el-input v-model="formData.Recommender" :clearable="true"  placeholder="请输入入职介绍人" />
            </el-form-item>
            <el-form-item label="RecommMobile字段:"  prop="RecommMobile" >
              <el-input v-model="formData.RecommMobile" :clearable="true"  placeholder="请输入RecommMobile字段" />
            </el-form-item>
            <el-form-item label="状态，1--正常，2--离职，3--黑名单:"  prop="Status" >
              <el-input v-model.number="formData.Status" :clearable="true" placeholder="请输入状态，1--正常，2--离职，3--黑名单" />
            </el-form-item>
            <el-form-item label="删除标记:"  prop="DeleteMark" >
              <el-input v-model.number="formData.DeleteMark" :clearable="true" placeholder="请输入删除标记" />
            </el-form-item>
            <el-form-item label="修改时间:"  prop="LeaveDate" >
              <el-date-picker v-model="formData.LeaveDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="有效标志:"  prop="EnabledMark" >
              <el-input v-model.number="formData.EnabledMark" :clearable="true" placeholder="请输入有效标志" />
            </el-form-item>
            <el-form-item label="备注:"  prop="Description" >
              <el-input v-model="formData.Description" :clearable="true"  placeholder="请输入备注" />
            </el-form-item>
            <el-form-item label="创建时间:"  prop="CreateDate" >
              <el-date-picker v-model="formData.CreateDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="创建用户主键:"  prop="CreateUserId" >
              <el-input v-model="formData.CreateUserId" :clearable="true"  placeholder="请输入创建用户主键" />
            </el-form-item>
            <el-form-item label="创建用户:"  prop="CreateUserName" >
              <el-input v-model="formData.CreateUserName" :clearable="true"  placeholder="请输入创建用户" />
            </el-form-item>
            <el-form-item label="修改时间:"  prop="ModifyDate" >
              <el-date-picker v-model="formData.ModifyDate" type="date" style="width:100%" placeholder="选择日期" :clearable="true"  />
            </el-form-item>
            <el-form-item label="修改用户主键:"  prop="ModifyUserId" >
              <el-input v-model="formData.ModifyUserId" :clearable="true"  placeholder="请输入修改用户主键" />
            </el-form-item>
            <el-form-item label="修改用户:"  prop="ModifyUserName" >
              <el-input v-model="formData.ModifyUserName" :clearable="true"  placeholder="请输入修改用户" />
            </el-form-item>
          </el-form>
    </el-drawer>

    <el-drawer size="800" v-model="detailShow" :before-close="closeDetailShow" title="查看详情" destroy-on-close>
          <template #title>
             <div class="flex justify-between items-center">
               <span class="text-lg">查看详情</span>
             </div>
         </template>
        <el-descriptions :column="1" border>
                <el-descriptions-item label="员工ID">
                        {{ formData.EmployeeId }}
                </el-descriptions-item>
                <el-descriptions-item label="工号">
                        {{ formData.EnCode }}
                </el-descriptions-item>
                <el-descriptions-item label="员工类型">
                        {{ formData.TypeId }}
                </el-descriptions-item>
                <el-descriptions-item label="姓名">
                        {{ formData.FullName }}
                </el-descriptions-item>
                <el-descriptions-item label="性别">
                        {{ formData.Gender }}
                </el-descriptions-item>
                <el-descriptions-item label="头像">
                        {{ formData.HeadPic }}
                </el-descriptions-item>
                <el-descriptions-item label="证件类型">
                        {{ formData.IDType }}
                </el-descriptions-item>
                <el-descriptions-item label="身份证号码">
                        {{ formData.IDNumber }}
                </el-descriptions-item>
                <el-descriptions-item label="身份证有效期">
                        {{ formData.IDValidityDate }}
                </el-descriptions-item>
                <el-descriptions-item label="出生日期">
                      {{ formatDate(formData.Birthday) }}
                </el-descriptions-item>
                <el-descriptions-item label="发证机关">
                        {{ formData.Organ }}
                </el-descriptions-item>
                <el-descriptions-item label="家庭地址">
                        {{ formData.FamilyAddress }}
                </el-descriptions-item>
                <el-descriptions-item label="健康状态">
                        {{ formData.Health }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位类型">
                        {{ formData.PostType }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位性质">
                        {{ formData.PostNature }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位类别">
                        {{ formData.PostClass }}
                </el-descriptions-item>
                <el-descriptions-item label="职位">
                        {{ formData.JobName }}
                </el-descriptions-item>
                <el-descriptions-item label="职称">
                        {{ formData.JobTitle }}
                </el-descriptions-item>
                <el-descriptions-item label="员工等级">
                        {{ formData.Rank }}
                </el-descriptions-item>
                <el-descriptions-item label="RankName字段">
                        {{ formData.RankName }}
                </el-descriptions-item>
                <el-descriptions-item label="CompanyId字段">
                        {{ formData.CompanyId }}
                </el-descriptions-item>
                <el-descriptions-item label="所属部门">
                        {{ formData.DepartmentId }}
                </el-descriptions-item>
                <el-descriptions-item label="所属部门">
                        {{ formData.DepartmentClass }}
                </el-descriptions-item>
                <el-descriptions-item label="部门类别">
                        {{ formData.PostId }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位名称">
                        {{ formData.PostName }}
                </el-descriptions-item>
                <el-descriptions-item label="级别">
                        {{ formData.GradeId }}
                </el-descriptions-item>
                <el-descriptions-item label="级别分类">
                        {{ formData.GradeClass }}
                </el-descriptions-item>
                <el-descriptions-item label="简历Id">
                        {{ formData.ResumeId }}
                </el-descriptions-item>
                <el-descriptions-item label="入职日期">
                      {{ formatDate(formData.JoinDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="试用期截止日期">
                      {{ formatDate(formData.TrialEndTime) }}
                </el-descriptions-item>
                <el-descriptions-item label="IsTrial字段">
                        {{ formData.IsTrial }}
                </el-descriptions-item>
                <el-descriptions-item label="TrailAuditMark字段">
                        {{ formData.TrailAuditMark }}
                </el-descriptions-item>
                <el-descriptions-item label="STrailAuditMark字段">
                        {{ formData.STrailAuditMark }}
                </el-descriptions-item>
                <el-descriptions-item label="加薪日期">
                      {{ formatDate(formData.TrailRaiseDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="IsTrailRaise字段">
                        {{ formData.IsTrailRaise }}
                </el-descriptions-item>
                <el-descriptions-item label="ID卡号">
                        {{ formData.IdCard }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位奖金生效日期">
                      {{ formatDate(formData.EffectiveDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="国籍">
                        {{ formData.Country }}
                </el-descriptions-item>
                <el-descriptions-item label="籍贯">
                        {{ formData.Native }}
                </el-descriptions-item>
                <el-descriptions-item label="民族">
                        {{ formData.Nation }}
                </el-descriptions-item>
                <el-descriptions-item label="最高学历">
                        {{ formData.Education }}
                </el-descriptions-item>
                <el-descriptions-item label="手提电话">
                        {{ formData.Mobile }}
                </el-descriptions-item>
                <el-descriptions-item label="婚姻状况">
                        {{ formData.Marriage }}
                </el-descriptions-item>
                <el-descriptions-item label="考勤卡号">
                        {{ formData.AttendanceCode }}
                </el-descriptions-item>
                <el-descriptions-item label="工齡起算日">
                      {{ formatDate(formData.WorkageCountOn) }}
                </el-descriptions-item>
                <el-descriptions-item label="工资薪酬ID">
                        {{ formData.SalaryId }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位奖金类型">
                        {{ formData.PostBonusId }}
                </el-descriptions-item>
                <el-descriptions-item label="岗位奖金金额">
                        {{ formData.BonusWage }}
                </el-descriptions-item>
                <el-descriptions-item label="放假组别">
                        {{ formData.HolidayGroupId }}
                </el-descriptions-item>
                <el-descriptions-item label="考勤组别">
                        {{ formData.AttendanceGroupId }}
                </el-descriptions-item>
                <el-descriptions-item label="地区">
                        {{ formData.Area }}
                </el-descriptions-item>
                <el-descriptions-item label="UrgentContacts字段">
                        {{ formData.UrgentContacts }}
                </el-descriptions-item>
                <el-descriptions-item label="UrgentContactPhone字段">
                        {{ formData.UrgentContactPhone }}
                </el-descriptions-item>
                <el-descriptions-item label="入职介绍人">
                        {{ formData.Recommender }}
                </el-descriptions-item>
                <el-descriptions-item label="RecommMobile字段">
                        {{ formData.RecommMobile }}
                </el-descriptions-item>
                <el-descriptions-item label="状态，1--正常，2--离职，3--黑名单">
                        {{ formData.Status }}
                </el-descriptions-item>
                <el-descriptions-item label="删除标记">
                        {{ formData.DeleteMark }}
                </el-descriptions-item>
                <el-descriptions-item label="修改时间">
                      {{ formatDate(formData.LeaveDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="有效标志">
                        {{ formData.EnabledMark }}
                </el-descriptions-item>
                <el-descriptions-item label="备注">
                        {{ formData.Description }}
                </el-descriptions-item>
                <el-descriptions-item label="创建时间">
                      {{ formatDate(formData.CreateDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="创建用户主键">
                        {{ formData.CreateUserId }}
                </el-descriptions-item>
                <el-descriptions-item label="创建用户">
                        {{ formData.CreateUserName }}
                </el-descriptions-item>
                <el-descriptions-item label="修改时间">
                      {{ formatDate(formData.ModifyDate) }}
                </el-descriptions-item>
                <el-descriptions-item label="修改用户主键">
                        {{ formData.ModifyUserId }}
                </el-descriptions-item>
                <el-descriptions-item label="修改用户">
                        {{ formData.ModifyUserName }}
                </el-descriptions-item>
        </el-descriptions>
    </el-drawer>
  </div>
</template>

<script setup>
import {
  createHrEmployee,
  deleteHrEmployee,
  deleteHrEmployeeByIds,
  updateHrEmployee,
  findHrEmployee,
  syncHrUserBatch,
  getHrEmployeeList
} from '@/api/hrEmployee'

// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict, ReturnArrImg, onDownloadFile } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref, reactive } from 'vue'

defineOptions({
    name: 'HrEmployee'
})

// 自动化生成的字典（可能为空）以及字段
const formData = ref({
        EmployeeId: '',
        EnCode: '',
        TypeId: '',
        FullName: '',
        Gender: '',
        HeadPic: '',
        IDType: '',
        IDNumber: '',
        IDValidityDate: '',
        Birthday: new Date(),
        Organ: '',
        FamilyAddress: '',
        Health: '',
        PostType: '',
        PostNature: '',
        PostClass: '',
        JobName: '',
        JobTitle: '',
        Rank: '',
        RankName: '',
        CompanyId: '',
        DepartmentId: '',
        DepartmentClass: '',
        PostId: '',
        PostName: '',
        GradeId: '',
        GradeClass: '',
        ResumeId: '',
        JoinDate: new Date(),
        TrialEndTime: new Date(),
        TrailAuditMark: 0,
        STrailAuditMark: 0,
        TrailRaiseDate: new Date(),
        IdCard: '',
        EffectiveDate: new Date(),
        Country: '',
        Native: '',
        Nation: '',
        Education: '',
        Mobile: '',
        Marriage: '',
        AttendanceCode: '',
        WorkageCountOn: new Date(),
        SalaryId: '',
        PostBonusId: '',
        BonusWage: 0,
        HolidayGroupId: '',
        AttendanceGroupId: '',
        Area: '',
        UrgentContacts: '',
        UrgentContactPhone: '',
        Recommender: '',
        RecommMobile: '',
        Status: 0,
        DeleteMark: 0,
        LeaveDate: new Date(),
        EnabledMark: 0,
        Description: '',
        CreateDate: new Date(),
        CreateUserId: '',
        CreateUserName: '',
        ModifyDate: new Date(),
        ModifyUserId: '',
        ModifyUserName: '',
        })


// 验证规则
const rule = reactive({
})

const searchRule = reactive({
  createdAt: [
    { validator: (rule, value, callback) => {
      if (searchInfo.value.startCreatedAt && !searchInfo.value.endCreatedAt) {
        callback(new Error('请填写结束日期'))
      } else if (!searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt) {
        callback(new Error('请填写开始日期'))
      } else if (searchInfo.value.startCreatedAt && searchInfo.value.endCreatedAt && (searchInfo.value.startCreatedAt.getTime() === searchInfo.value.endCreatedAt.getTime() || searchInfo.value.startCreatedAt.getTime() > searchInfo.value.endCreatedAt.getTime())) {
        callback(new Error('开始日期应当早于结束日期'))
      } else {
        callback()
      }
    }, trigger: 'change' }
  ],
})

const elFormRef = ref()
const elSearchFormRef = ref()

// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})

// 重置
const onReset = () => {
  searchInfo.value = {}
  getTableData()
}

// 搜索
const onSubmit = () => {
  elSearchFormRef.value?.validate(async(valid) => {
    if (!valid) return
    page.value = 1
    pageSize.value = 10
    getTableData()
  })
}

// 分页
const handleSizeChange = (val) => {
  pageSize.value = val
  getTableData()
}

// 修改页面容量
const handleCurrentChange = (val) => {
  page.value = val
  getTableData()
}

// 查询
const getTableData = async() => {
  const table = await getHrEmployeeList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
  if (table.code === 0) {
    tableData.value = table.data.list
    total.value = table.data.total
    page.value = table.data.page
    pageSize.value = table.data.pageSize
  }
}

getTableData()

// ============== 表格控制部分结束 ===============

// 获取需要的字典 可能为空 按需保留
const setOptions = async () =>{
}

// 获取需要的字典 可能为空 按需保留
setOptions()


// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
    multipleSelection.value = val
}

// 删除行
const deleteRow = (row) => {
    ElMessageBox.confirm('确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }).then(() => {
            deleteHrEmployeeFunc(row)
        })
    }

// 多选删除
const onDelete = async() => {
  ElMessageBox.confirm('确定要删除吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(async() => {
      const IDs = []
      if (multipleSelection.value.length === 0) {
        ElMessage({
          type: 'warning',
          message: '请选择要删除的数据'
        })
        return
      }
      multipleSelection.value &&
        multipleSelection.value.map(item => {
          IDs.push(item.ID)
        })
      const res = await deleteHrEmployeeByIds({ IDs })
      if (res.code === 0) {
        ElMessage({
          type: 'success',
          message: '删除成功'
        })
        if (tableData.value.length === IDs.length && page.value > 1) {
          page.value--
        }
        getTableData()
      }
      })
    }

// 行为控制标记（弹窗内部需要增还是改）
const type = ref('')

// 更新行
const updateHrEmployeeFunc = async(row) => {
    const res = await findHrEmployee({ ID: row.ID })
    type.value = 'update'
    if (res.code === 0) {
        formData.value = res.data.rehrEmployee
        dialogFormVisible.value = true
    }
}


// 删除行
const deleteHrEmployeeFunc = async (row) => {
    const res = await deleteHrEmployee({ ID: row.ID })
    if (res.code === 0) {
        ElMessage({
                type: 'success',
                message: '删除成功'
            })
            if (tableData.value.length === 1 && page.value > 1) {
            page.value--
        }
        getTableData()
    }
}

// 弹窗控制标记
const dialogFormVisible = ref(false)


// 查看详情控制标记
const detailShow = ref(false)


// 打开详情弹窗
const openDetailShow = () => {
  detailShow.value = true
}


// 打开详情
const getDetails = async (row) => {
  // 打开弹窗
  const res = await findHrEmployee({ ID: row.ID })
  if (res.code === 0) {
    formData.value = res.data.rehrEmployee
    openDetailShow()
  }
}


// 关闭详情弹窗
const closeDetailShow = () => {
  detailShow.value = false
  formData.value = {
          EmployeeId: '',
          EnCode: '',
          TypeId: '',
          FullName: '',
          Gender: '',
          HeadPic: '',
          IDType: '',
          IDNumber: '',
          IDValidityDate: '',
          Birthday: new Date(),
          Organ: '',
          FamilyAddress: '',
          Health: '',
          PostType: '',
          PostNature: '',
          PostClass: '',
          JobName: '',
          JobTitle: '',
          Rank: '',
          RankName: '',
          CompanyId: '',
          DepartmentId: '',
          DepartmentClass: '',
          PostId: '',
          PostName: '',
          GradeId: '',
          GradeClass: '',
          ResumeId: '',
          JoinDate: new Date(),
          TrialEndTime: new Date(),
          TrailAuditMark: 0,
          STrailAuditMark: 0,
          TrailRaiseDate: new Date(),
          IdCard: '',
          EffectiveDate: new Date(),
          Country: '',
          Native: '',
          Nation: '',
          Education: '',
          Mobile: '',
          Marriage: '',
          AttendanceCode: '',
          WorkageCountOn: new Date(),
          SalaryId: '',
          PostBonusId: '',
          BonusWage: 0,
          HolidayGroupId: '',
          AttendanceGroupId: '',
          Area: '',
          UrgentContacts: '',
          UrgentContactPhone: '',
          Recommender: '',
          RecommMobile: '',
          Status: 0,
          DeleteMark: 0,
          LeaveDate: new Date(),
          EnabledMark: 0,
          Description: '',
          CreateDate: new Date(),
          CreateUserId: '',
          CreateUserName: '',
          ModifyDate: new Date(),
          ModifyUserId: '',
          ModifyUserName: '',
          }
}


// 同步Hr用户
function syncHrUser(params) {
  syncHrUserBatch().then((res) => {
    if (res.code == 0) {
      ElMessage({
        type: 'success',
        message: '同步成功'
      })
    }
  });
}


// 打开弹窗
const openDialog = () => {
    type.value = 'create'
    dialogFormVisible.value = true
}

// 关闭弹窗
const closeDialog = () => {
    dialogFormVisible.value = false
    formData.value = {
        EmployeeId: '',
        EnCode: '',
        TypeId: '',
        FullName: '',
        Gender: '',
        HeadPic: '',
        IDType: '',
        IDNumber: '',
        IDValidityDate: '',
        Birthday: new Date(),
        Organ: '',
        FamilyAddress: '',
        Health: '',
        PostType: '',
        PostNature: '',
        PostClass: '',
        JobName: '',
        JobTitle: '',
        Rank: '',
        RankName: '',
        CompanyId: '',
        DepartmentId: '',
        DepartmentClass: '',
        PostId: '',
        PostName: '',
        GradeId: '',
        GradeClass: '',
        ResumeId: '',
        JoinDate: new Date(),
        TrialEndTime: new Date(),
        TrailAuditMark: 0,
        STrailAuditMark: 0,
        TrailRaiseDate: new Date(),
        IdCard: '',
        EffectiveDate: new Date(),
        Country: '',
        Native: '',
        Nation: '',
        Education: '',
        Mobile: '',
        Marriage: '',
        AttendanceCode: '',
        WorkageCountOn: new Date(),
        SalaryId: '',
        PostBonusId: '',
        BonusWage: 0,
        HolidayGroupId: '',
        AttendanceGroupId: '',
        Area: '',
        UrgentContacts: '',
        UrgentContactPhone: '',
        Recommender: '',
        RecommMobile: '',
        Status: 0,
        DeleteMark: 0,
        LeaveDate: new Date(),
        EnabledMark: 0,
        Description: '',
        CreateDate: new Date(),
        CreateUserId: '',
        CreateUserName: '',
        ModifyDate: new Date(),
        ModifyUserId: '',
        ModifyUserName: '',
        }
}
// 弹窗确定
const enterDialog = async () => {
     elFormRef.value?.validate( async (valid) => {
             if (!valid) return
              let res
              switch (type.value) {
                case 'create':
                  res = await createHrEmployee(formData.value)
                  break
                case 'update':
                  res = await updateHrEmployee(formData.value)
                  break
                default:
                  res = await createHrEmployee(formData.value)
                  break
              }
              if (res.code === 0) {
                ElMessage({
                  type: 'success',
                  message: '创建/更改成功'
                })
                closeDialog()
                getTableData()
              }
      })
}

</script>

<style>

</style>
